ajax请求如何获取Header中头信息 |
您所在的位置:网站首页 › ajax 获取响应头 › ajax请求如何获取Header中头信息 |
在ajax中,怎样获取Header中头信息呢? 通过原生的JavaScriptvar url = 'test.php'; function createXmlHttp() { var xmlhttp = null; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); }else{// code for IE6, IE5 xmlhttp = new ActiveXO相应bject("Microsoft.XMLHTTP"); } return xmlhttp; } var xmlhttp = createXmlHttp(); xmlhttp.open("GET", url, true); xmlhttp.send(); xmlhttp.onreadystatechange=function(){//设置状态发生变化时候监听函数 if(xmlhttp.readyState ==4 && 200 == xmlhttp.status){ console.log(xmlhttp.getAllResponseHeaders());//获取所有的响应头消息 //console.log(xmlhttp.getResponseHeader('server')); //获取服务器信息 } }通过JQuery获取var url = 'test.php'; $.get(url, function(data, statusTest, xhr){ console.log(xhr); console.log(xhr.getAllResponseHeaders());//获取所有的响应头消息 //console.log(xhr.getResponseHeader('server'));//获取服务器信息 });返回的结果如下: ajax获取重定向后的url有的时候,当服务端中进行了重定向,譬如,当我们请求test.php文件时候,在test.php中重定向到test.2php文件。 test.php文件 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |